<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <template id="t1">
      <div>
        <button @click="log()">修改</button>
        <ul>
          <li v-for="(value,key,index) of user">{{value}}-{{key}}-{{index}}</li>
        </ul>
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      // 数据驱动视图
      const vm = new Vue({
        el: "#app",
        template: "#t1",
        data: {
          user: {
            name: "jack",
            age: 20,
            gender: "boy",
          },
        },
        methods: {
          log() {
            // 修改
            // this.user.name = "lili";
            // 添加
            // this.user.email = "lili@qq.com";
            // this.user = { ...this.user, email: "lili@qq.com" };
            // Object.defineProperty()
            // this.$set(this.user, "email", "lili@qq.com");
            this.$set(this.user, "phone", "180138387666");
            // 删除
            // delete this.user.age;
            // this.user = { ...this.user };
            this.$delete(this.user, "age");
          },
        },
      });
    </script>
  </body>
</html>
